﻿using System.Collections.Generic;
using Hidistro.Core;
using Hidistro.Core.Enums;
using Hidistro.Entities;
using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_CategoriesWithWindow : WebControl
    {
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(this.RendHtml());
        }

        public string RendHtml()
        {
            StringBuilder builder1 = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();
            builder1.AppendFormat("<div class=\"wnxd_category\" {0}><div class=\"wnxd_cat_list\">", this.hide == true ? "style=\"display:none;\"" : "");
            IList<CategoryInfo> list = CategoryBrowser.GetMaxSubCategories(0, this.MaxCNum);
            int i = 0;
            foreach (CategoryInfo sc in list)
            {
                builder1.Append("<div class=\"wnxd_fenlei\"><div class=\"wnxd_fenlei_img\">");
                builder1.AppendFormat("<img width=\"100%\" height=\"100%\" src=\"http://image.juseshop.com/images/js-submenu{0}.jpg\" /></div>", sc.CategoryId);
                builder1.AppendFormat("<a href=\"{0}\">{1}</a>", Globals.GetSiteUrls().SubCategory(sc.CategoryId, sc.RewriteName, sc.ParentRewriteName), sc.Name);
                builder1.Append("</div>");
                builder2.Append("<div class=\"wnxd_cat\">");
                builder2.Append("<div class=\"wnxd_ca\">");
                IList<CategoryInfo> sclist = CategoryBrowser.GetMaxSubCategories(sc.CategoryId, 0x3e8);
                foreach (CategoryInfo a in sclist)
                {
                    builder2.Append("<div class=\"wnxd_jianduan\">");
                    builder2.AppendFormat("<a href=\"{0}\">{1}</a>", Globals.GetSiteUrls().SubCategory(a.CategoryId, a.RewriteName, sc.ParentRewriteName), a.Name);
                    builder2.Append("</div>");
                }
                builder2.Append("</div><div class=\"wnxd_brand\">");
                builder2.AppendFormat("<div>品牌推荐：<b><a href=\"{0}\">更多品牌>></a></b></div>", Globals.GetSiteUrls().UrlData.FormatUrl("brandall"));
                DataTable bclist = CategoryBrowser.GetBrandCategories(sc.CategoryId, 12);
                foreach (DataRow row in bclist.Rows)
                {
                    builder2.AppendFormat("<a class=\"wnxd_logo\" href=\"{0}\"><img width=\"100%\" height=\"100%\" src=\"{1}\" /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("branddetails", row["BrandId"]), Globals.GetImgUrl(row["Logo"].ToString()));
                }
                //builder2.Append("</div></div>");
                builder2.AppendFormat("</div><div style=\"position:absolute;top:{0}px;left:-2px;z-index:6;width:2px;height:68px;background-color:#fff;\"></div></div>", i * 70);
                i++;

            }
            builder1.Append("</div>");
            builder1.Append(builder2.ToString());
            builder1.Append("</div>");
            return builder1.ToString();
        }
        public int MaxCNum { get; set; }
        public bool hide { get; set; }
    }
}
